package com.zmn.mcc.services.impl.staff.staffperformance;

import com.zmn.mcc.model.entity.staff.staffperformance.StaffPerformance;
import com.zmn.mcc.model.entity.staff.staffperformance.StaffPerformanceQuery;
import com.zmn.mcc.persistence.interfaces.staff.staffperformance.StaffPerformanceDAO;
import com.zmn.mcc.services.interfaces.staff.staffperformance.StaffPerformanceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 描述: 员工绩效基础接口实现类
 *
 * @author tanghongjun
 * @since 2020-05-14 10:21:58
 **/
@Slf4j
@Service
public class StaffPerformanceServiceImpl implements StaffPerformanceService {

    private static final String TAG = "员工绩效基础服务接口";

    @Resource
    private StaffPerformanceDAO staffPerformanceDao;

    /**
     * 描述: 根据id查询数据
     *
     * @param performanceId id
     * @author tanghongjun
     * @since 2020-05-14 10:21:58
     **/
    @Override
    public StaffPerformance findById(Integer performanceId) {

        if (Objects.isNull(performanceId)) {
            log.error("[{}],根据id查询数据performanceId为null", TAG);
            return null;
        }
        return staffPerformanceDao.findById(performanceId);
    }

    /**
     * 描述: 按条件查询数据 支持分页
     *
     * @param query 查询对象
     * @author tanghongjun
     * @since 2020-05-14 10:21:58
     **/
    @Override
    public List<StaffPerformance> listPageByQuery(StaffPerformanceQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        int count = countByQuery(query);
        query.setTotalCount(count);
        return staffPerformanceDao.listPageByQuery(query);
    }

    /**
     * 描述: 按条件查询数据 不支持分页
     *
     * @param query 查询对象
     * @author tanghongjun
     * @since 2020-05-14 10:21:58
     **/
    @Override
    public List<StaffPerformance> listByQuery(StaffPerformanceQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        return staffPerformanceDao.listByQuery(query);
    }

    /**
     * 描述: 按条件查询数据 不支持分页
     *
     * @param query 查询对象
     * @author tanghongjun
     * @since 2020-05-14 10:21:58
     **/
    @Override
    public Integer countByQuery(StaffPerformanceQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件统计数据,query为null", TAG);
            return null;
        }
        return staffPerformanceDao.countByQuery(query);
    }


    /**
     * 描述: 根据id修改数据 id为必传
     *
     * @param staffPerformance 待修改数据
     * @return java.lang.Integer
     * @author tanghongjun
     * @since 2020-05-14 10:21:58
     **/
    @Override
    public Integer updateStaffPerformanceByKey(StaffPerformance staffPerformance) {

        if (Objects.isNull(staffPerformance.getPerformanceId())) {
            log.error("[{}],根据id修改数据,staffPerformance为null", TAG);
            return null;
        }
        return staffPerformanceDao.updateStaffPerformanceByKey(staffPerformance);
    }

    @Override
    public Integer updateStaffId() {
        return staffPerformanceDao.updateStaffId();
    }

    /**
     * 描述: 新增数据
     *
     * @param staffPerformance 待新增数据
     * @return java.lang.Integer 主键key
     * @author tanghongjun
     * @since 2020-05-14 10:21:58
     **/
    @Override
    public Integer insert(StaffPerformance staffPerformance) {

        if (Objects.isNull(staffPerformance)) {
            log.error("[{}],新增数据,staffPerformance为null", TAG);
            return null;
        }
        return staffPerformanceDao.insert(staffPerformance);
    }

    @Override
    public void insertBatch(List<StaffPerformance> performanceList) {
        staffPerformanceDao.insertBatch(performanceList);
    }

    /**
     * 描述: 根据主键删除数据
     *
     * @param performanceId
     * @return: 执行结果码
     * @auther: tanghongjun
     * @since: 2020-05-14 10:21:58
     */
    @Override
    public Integer deleteByKey(Integer performanceId) {

        if (Objects.isNull(performanceId)) {
            log.error("[{}],根据id删除数据,performanceId为null", TAG);
            return null;
        }
        return staffPerformanceDao.deleteByKey(performanceId);
    }

}